package com.mayikt;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * @ClassName Test36
 * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com
 * @Version V1.0
 **/
public class Test36 {
    private static Object lock = new Object();

    public static void main(String[] args) throws InterruptedException {
//        new Thread(() -> {
//            System.out.println("1");
//            synchronized (lock) {
//                try {
//                    //当前线程释放锁，当线程变为阻塞状态。
//                    lock.wait();
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                System.out.println("2");
//            }
//        }).start();
//        Thread.sleep(3000);
//        System.out.println("3");
//        synchronized (lock) {
//            //唤醒刚才阻塞的线程
//            lock.notify();
//        }
        //将aqs状态 state 设置为2
        CountDownLatch countDownLatch = new CountDownLatch(1);
        new Thread(() -> {
            System.out.println("1");
            try {
                // 变为阻塞状态 同时释放锁
                countDownLatch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("2");
        }).start();
        Thread.sleep(3000);
        System.out.println("3");
//        countDownLatch.countDown();// aqs 状态-1 只有aqs 的状态为0的情况下 才会唤醒子线程
//        countDownLatch.countDown();




    }
}
